﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MetroStyle
{
    public partial class FormControl : UserControl
    {
        private double frmopacity;
        public FormControl()
        {
            InitializeComponent();
            if (!ShowMaxBox)
                this.Width = 41;
            if (!ShowMaxandMinBox)
                this.Width = 25;
        }
        public System.Windows.Forms.Form MainForm { get; set; }
        public bool ShowMaxandMinBox { get { return lb_Min.Visible; } set { lb_Max.Visible = value; lb_Min.Visible = value; } }
        public bool ShowMaxBox { get { return lb_Max.Visible; } set { lb_Max.Visible = value; } }
        public bool ShowMinAmtion { get; set; }
        /// <summary>
        /// 最小化动画的速度，1-100
        /// </summary>
        public int MinAmtion { get; set; }
        
        private void lb_close_Click(object sender, EventArgs e)
        {
            MainForm.Close();
        }

        private void lb_Max_Click(object sender, EventArgs e)
        {
            
            if (MainForm.WindowState == System.Windows.Forms.FormWindowState.Maximized)
            {
                MainForm.WindowState = System.Windows.Forms.FormWindowState.Normal;
            }
            else
            {
                MainForm.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            }
        }

        private void lb_Min_Click(object sender, EventArgs e)
        {
            if (ShowMinAmtion)
            {
                frmopacity = MainForm.Opacity;
                Timer_Amtion.Enabled = true;
            }
            else
            {
                MainForm.WindowState = System.Windows.Forms.FormWindowState.Minimized;
            }
        }

        private void lb_close_MouseHover(object sender, EventArgs e)
        {
            ((Label)sender).BorderStyle = BorderStyle.FixedSingle;
        }

        private void lb_close_MouseLeave(object sender, EventArgs e)
        {
            ((Label)sender).BorderStyle = BorderStyle.None;
        }

        private void Timer_Amtion_Tick(object sender, EventArgs e)
        {
            double o = MainForm.Opacity * 100;
            MainForm.Opacity = (o - 1 - MinAmtion) / 100;
            if (MainForm.Opacity <= 0)
            {
                Timer_Amtion.Enabled = false;
                MainForm.WindowState = System.Windows.Forms.FormWindowState.Minimized;
                MainForm.Opacity = frmopacity;
            }
        }
    }
}
